package com.bootcamp.javase.static_0828;

/*定义一个JavaStudent类：
	要求包含4个成员变量 String name, int age, String gender, int stuId，double score
	其中score用来表示该学生的Java成绩
	然后定义一些构造方法
然后：
   （1）修改print()方法，输出学生对象的name，stuId，gender，age，score的值(即输出学生信息)
   （2）增加一个构造方法，能够给学生对象全体成员变量赋值，要求使用this简化代码
   （2）创建五个该类的对象，将它们装入数组，遍历输出每个学生的信息
   		然后计算并输出这五个学生Java语言成绩的平均值
        提示：数组既可以存储基本数据类型的值，也可以存储引用数据类型的值*/

public class JavaStudent {
    String name;
    int age;
    String gender;
    int stuId;
    double score;

    public JavaStudent(String name, int age, String gender, int stuId, double score) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.stuId = stuId;
        this.score = score;
    }

    public void print() {
        System.out.println("[ name: " + this.name +
                "\tage: " + this.age +
                "\tgender: " + this.gender +
                "\tstuId: " + this.stuId +
                "\tscore: " + this.score +
                " ]");
    }
}

class StudentDemo {
    public static void main(String[] args) {
        JavaStudent[] stu = new JavaStudent[5];
        // create 5 student object
        stu[0] = new JavaStudent("Charle", 18, "male", 10086, 97.1);
        stu[1] = new JavaStudent("Webster", 20, "male", 10033, 67.1);
        stu[2] = new JavaStudent("Emily", 21, "female", 10246, 100);
        stu[3] = new JavaStudent("Jobs", 18, "male", 10897, 56.5);
        stu[4] = new JavaStudent("Lily", 17, "female", 10081, 91.5);

        double totalScore = 0.0;
        for (int i = 0; i < stu.length; i++) {
            stu[i].print();
            totalScore += stu[i].score;
        }
        System.out.println("the average score is: " + totalScore / 5);
    }
}
